package com.example.yichuangyun.mvvm.ui.fragment.view;

import androidx.lifecycle.MutableLiveData;

import com.example.yichuangyun.config.Constant;
import com.example.yichuangyun.model.company.CustomInfoDataModel;
import com.example.yichuangyun.mvvm.base.BaseViewModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseNetCallback;
import com.google.gson.Gson;

import java.util.Map;

public class CustomInfoViewModel extends BaseViewModel {

    public MutableLiveData<CustomInfoDataModel> customInfoDataModelMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<String> errorMutableLiveData = new MutableLiveData<>();

    /**
     * 自主信息列表
     */
    public void getCustomList(Map<String, Object> map) {
        map.put("pageSize", Constant.pageSize);
        addSubscribe(mRetrofitHelper.getCustomList(new Gson().toJson(map)).subscribeWith(new BaseNetCallback<CustomInfoDataModel>() {

            @Override
            public void onSuccess(BaseModel<CustomInfoDataModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    if (null != baseModel.getData()) {
                        customInfoDataModelMutableLiveData.setValue(baseModel.getData());
                    }
                } else {
                    errorMutableLiveData.setValue(baseModel.getMsg());
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                errorMutableLiveData.setValue(message);
            }
        }));
    }
}
